package com.bawei.room.db

import androidx.room.Database
import androidx.room.RenameColumn
import androidx.room.RenameTable
import androidx.room.RoomDatabase
import androidx.room.migration.AutoMigrationSpec
import com.bawei.room.dao.UserInfoDao
import com.bawei.room.dao.VideoInfoDao
import com.bawei.room.table.UserDaoEntity
import com.bawei.room.table.VideoDaoEntity

/**
 * Author: Jason Zhang
 * Date: 2024/8/20
 * Desc: 数据库实体
 */

@Database(
    entities =[UserDaoEntity::class, VideoDaoEntity::class], //数据库中包含哪些表格的实体对象
    version = 1,  //数据库版本号
    exportSchema = false, //是否导出数据库
    autoMigrations = [
//        AutoMigration(from = 1, to = 2, spec = AppDataBase.UserInfoAutoMigration::class),
//        AutoMigration(from = 1, to = 2, spec = AppDataBase.UserInfoColumnAutoMigration::class),
    ] //数据库升级
)
abstract class AppDataBase : RoomDatabase(){

    abstract fun getUserInfoDao(): UserInfoDao

    abstract fun getVideoInfoDao(): VideoInfoDao

    //用于升级的时候修改表名
    @RenameTable(fromTableName = "user_table", toTableName = "user_info_table")
    class UserInfoAutoMigration : AutoMigrationSpec

    @RenameColumn(tableName = "user_table", fromColumnName = "name", toColumnName = "user_name")
    class UserInfoColumnAutoMigration : AutoMigrationSpec


}